<?php

namespace common\models\member;

use Yii;

/**
 * This is the model class for table "members".
 *
 * @property integer $id
 * @property string $user
 * @property string $password
 * @property string $pass_not_md5
 * @property string $client_id
 * @property string $on_line
 */
class Members extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'members';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user', 'password'], 'required' ,'message' => '账号密码不能为空'],
            [['user', 'password','pass_not_md5'], 'string', 'max' => 255],
            [['on_line'],'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user' => 'User',
            'password' => 'Password',
            'pass_not_md5' => 'Pass Not Md5',
        ];
    }
    public function register($member){
        $this->user = $member['Members']['user'];
        $this->password = md5($member['Members']['password']);
        $this->pass_not_md5 = $member['Members']['password'];
        $this->on_line = 1;
        if($this->save()){
            return $this->primaryKey;
        }else{
            return false;
        }
    }
    public function login($member){
        $data = self::find()->where(['user'=>$member['Members']['user'],'password'=>md5($member['Members']['password'])])->asArray()->one();
        return empty($data)?false : $data;
    }
}
